package chuyentrung.racehorses;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ToggleButton;

public class ScreenMainMenu extends Activity implements OnClickListener{
	private ImageView newGameBtn, optionBtn, helpBtn, quitBtn;
	private ImageView infoBtn;
	private ToggleButton musicBtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		/*getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
		setContentView(R.layout.main_menu);
		
		newGameBtn = (ImageView) findViewById(R.id.newGameBtn);
		optionBtn = (ImageView) findViewById(R.id.optionBtn);
		helpBtn = (ImageView) findViewById(R.id.helpBtn);
		quitBtn = (ImageView) findViewById(R.id.quitBtn);
		infoBtn = (ImageView) findViewById(R.id.infoBtn);
		musicBtn= (ToggleButton) findViewById(R.id.musicBtn);
		
		newGameBtn.setOnClickListener(this);
		optionBtn.setOnClickListener(this);
		helpBtn.setOnClickListener(this);
		quitBtn.setOnClickListener(this);
		infoBtn.setOnClickListener(this);
		musicBtn.setOnClickListener(this);
		
		Assets.playMusic();
	}
	
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		Assets.playSound(Assets.clickSnd);
		
		switch (id){
		case R.id.newGameBtn :
			startActivity(new Intent(ScreenMainMenu.this, ScreenSettingGame.class));
			break;
			
		case R.id.optionBtn :
			startActivity(new Intent(ScreenMainMenu.this, ScreenOption.class));
			break;
			
		case R.id.helpBtn :
			startActivity(new Intent(ScreenMainMenu.this, ScreenHelp.class));
			break;
			
		case R.id.quitBtn :
			finish();
			break;
			
		case R.id.infoBtn :			
			startActivity(new Intent(ScreenMainMenu.this, ScreenAbout.class)); 
			break;
			
		case R.id.musicBtn :			
			GamePreferences.musicEnabled = !GamePreferences.musicEnabled;
			if (GamePreferences.musicEnabled)
				Assets.playMusic();
			else 
				Assets.musicOutGame.stop();
			break;

			default : break;
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if (GamePreferences.musicEnabled)
			musicBtn.setChecked(true);
		else
			musicBtn.setChecked(false);
	}



	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Assets.music.stop();
		Assets.music.dispose();
	}
	
	
}
